﻿//  Key Tracker - An application to keep track of product keys.
//
//  Copyright (c) 2009  Shawn Rakowski
//
//  Permission is hereby granted, free of charge, to any person
//  obtaining a copy of this software and associated documentation
//  files (the "Software"), to deal in the Software without
//  restriction, including without limitation the rights to use,
//  copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following
//  conditions:
//
//  The above copyright notice and this permission notice shall be
//  included in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//  OTHER DEALINGS IN THE SOFTWARE.
// --------------------------------------------------------------------------//
/*      Tables.cs 
 *      
 * 
 *      Key Tracker Project   
 *      
 *      CODE FILE DESCRIPTION:
 *      
 *          This code file contains classes related to the tables in an SQLite 
 *          Key Tracker Database. It includes classes for each table. It also
 *          contains a class with all SQL information for the creation and upkeep
 *          of these tables.
 *          
 *      AUTHOR(S):
 *      
 *          Shawn Rakowski
 * 
 *      CLASSES:
 *      
 *          KeyRec
 *          ProductRec
 *          SQLCommands
 *      
 *      MODIFICATION HISTORY:
 *      
 *          06-AUG-2008     Shawn Rakowski      New Program.
 *          17-AUG-2008     Shawn Rakowski      Added product_process and AlterTablesQueue
 * 
 * 
 */

#region Using Statements

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#endregion

namespace KeyTracker.Classes
{
    #region Table Enumerations

    public enum PRODUCT_COLUMNS { PRODUCT_ID = 0, PRODUCT_NAME = 1, PRODUCT_PROCESS = 2 };
    public enum KEY_COLUMNS { KEY_ID = 0, PRODUCT_ID = 1, KEY_VALUE = 2 };
    
    #endregion

    class KeyRec
    {
        #region Class Level Variables

        private int kId;
        private int pId;
        private string kValue;

        #endregion

        #region Contructors

        /// <summary>
        /// Constructs a new KeyRec.
        /// </summary>
        /// <param name="keyId"></param>
        /// <param name="productId"></param>
        /// <param name="keyValue"></param>
        public KeyRec(int keyId, int productId, string keyValue)
        {
            kId = keyId;
            pId = productId;
            kValue = keyValue;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or Sets the Key ID.
        /// </summary>
        public int KeyId
        {
            set { kId = value; }
            get { return kId; }
        }

        /// <summary>
        /// Gets or Sets the Product ID.
        /// </summary>
        public int ProductId
        {
            set { pId = value; }
            get { return pId; }
        }

        /// <summary>
        /// Gets or Sets the Key Value.
        /// </summary>
        public string KeyValue
        {
            set { kValue = value; }
            get { return kValue; }
        }

        #endregion
    }

    class ProductRec
    {
        #region Class Level Variables
        
        private int 
            prodId;

        private string 
            prodName;

        private string
            installProcessName;

        #endregion

        #region Constructors

        /// <summary>
        /// Contructs a product record class.
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="productName"></param>
        public ProductRec(int productId, string productName)
        {
            prodId = productId;
            prodName = productName;
            installProcessName = "";
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or Sets the Product Name.
        /// </summary>
        public string ProductName
        {
            set { prodName = value; }
            get { return prodName; }
        }

        /// <summary>
        /// Gets or Sets the Product ID.
        /// </summary>
        public int ProductId
        {
            set { prodId = value; }
            get { return prodId; }
        }

        /// <summary>
        /// Gets or Sets the Install Process Name.
        /// </summary>
        public string ProductProcess
        {
            set { installProcessName = value; }
            get { return installProcessName; }
        }

        #endregion
    }

    class SQLCommands
    {
        #region Table Creation Strings

        private string
            createKeyRec = "create table key_rec (key_id integer primary key autoincrement unique, product_id integer, key_value text)", 
            createProdRec = "create table product_rec (product_id integer primary key autoincrement unique, product_name text, product_process text)";
        
        private Queue<string>
            createTablesQueue = new Queue<string>();

        #endregion

        #region Table Alter Strings

        private string
            alterProdRec = "alter table product_rec add product_process text;";

        private Queue<string>
            alterTablesQueue = new Queue<string>();

        #endregion

        #region Table Test Strings

        private string
            testKeyRec = "select key_id, product_id, key_value from key_rec;",
            testProdRec = "select product_id, product_name, product_process from product_rec;";

        private Queue<string>
            testTablesQueue = new Queue<string>();

        #endregion

        #region Constructors

        /// <summary>
        /// Constructs an SQLCommands class.
        /// </summary>
        public SQLCommands()
        {
            #region Fill Command Queues

            createTablesQueue.Enqueue(createKeyRec);
            createTablesQueue.Enqueue(createProdRec);

            alterTablesQueue.Enqueue(alterProdRec);

            testTablesQueue.Enqueue(testKeyRec);
            testTablesQueue.Enqueue(testProdRec);

            #endregion
        }

        #endregion

        #region Get SQL Queues

        public Queue<string> CreateTableQueue
        {
            get { return createTablesQueue; }
        }

        public Queue<string> AlterTablesQueue
        {
            get { return alterTablesQueue; }
        }

        public Queue<string> TestTablesQueue
        {
            get { return testTablesQueue; }
        }

        #endregion

        #region Get Creation Strings

        /// <summary>
        /// Gets the SQL Command to create the key_rec table.
        /// </summary>
        public string CreateKeyRecTable
        {
            get { return createKeyRec; }
        }

        /// <summary>
        /// Gets the SQL command to create the product_rec table.
        /// </summary>
        public string CreateProdKeyTable
        {
            get { return createProdRec; }
        }

        #endregion
    }
}
